define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/lists/index' + location.search,
                    add_url: 'order/lists/add',
                    edit_url: 'order/lists/edit',
                    del_url: 'order/lists/del',
                    multi_url: 'order/lists/multi',
                    import_url: 'order/lists/import',
                    table: 'order_lists',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'platform_name', title: __('Platform_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'ordersn', title: __('Ordersn'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'goodstitle', title: __('Goodstitle'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'time', title: __('Time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'paytype', title: __('Paytype'), searchList: {"wechat":__('Wechat'),"alipay":__('Alipay'),"unionpay":__('Unionpay')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'status', title: __('Status'), searchList: {"待付款":__('待付款'),"已支付":__('已支付'),"订单关闭":__('订单关闭'),"支付失败":__('支付失败'),"退款中":__('退款中'),"退款成功":__('退款成功'),"退款失败":__('退款失败')}, formatter: Table.api.formatter.status},

                        {field: 'notify_status', title: __('Notify_status'), formatter: function (value, row, index){
                            if (value == 1){
                                return '通知成功';
                            }else if(value == 2){
                                return '通知失败';
                            }
                            }},
                        {field: 'openid', title: __('Openid'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'callbackurl', title: __('Callbackurl'), operate: 'LIKE', formatter: Table.api.formatter.url},
                        // {field: 'nonce_str', title: __('Nonce_str'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'payplatform', title: __('Payplatform'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'platform', title: __('Platform'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'appid', title: __('Appid'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'merchant_no', title: __('Merchant_no'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'verifycode', title: __('Verifycode'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'bankorderno', title: __('Bankorderno'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'banktrxno', title: __('Banktrxno'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'bankcode', title: __('Bankcode'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'thirdfee', title: __('Thirdfee'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'trxno', title: __('Trxno'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'paystatus', title: __('Paystatus')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
